2.2 Environment Variables
U-BOOT utilizes environment variables to adjust its own execution sequence and configure system hardware parameters. Environment variables are case-sensitive and are stored as character strings within non-volatile storage media, such as an EEPROM or flash memory. The environment consists of standard predefined environment variables and custom user-defined variables. The most frequently encountered standard environment variables are detailed below.
2.2.1 autostart
When autostart is set to yes, y, Y, t, T, or 1, image files imported via the bootp, bootelf, dhcp, diskboot, nboot, nfs, rarpboot, scsiboot, tftpboot, or usbboot commands will automatically boot. If autostart contains any value other than those specified above, the image payload is merely loaded into memory but will not automatically execute. Images passed to bootm are copied to the memory space designated by the load address for decompression; leveraging this architectural trait allows arbitrary data blocks to be loaded into memory and decompressed on demand.
2.2.2 baudrate
This variable configures the transmission baud rate for the serial console port. Because U-BOOT is primarily deployed on embedded systems, the interactive control terminal typically runs on a host computer, communicating with the embedded target via a serial interface. This environment variable defines the communication speed across the UART line linking the host and the embedded platform.
2.2.3 bootdelay
This variable defines the wait time (in seconds) before the automatic boot sequence is initiated. After U-BOOT initializes in memory, if bootdelay is not equal to 0, it pauses for the specified duration. During this countdown period, if the user registers a keystroke on the keyboard, U-BOOT breaks out of the autoboot sequence and enters the interactive command interpretation state, enabling users to enter any of the U-BOOT commands listed previously. If the delay expires without a keystroke, U-BOOT automatically begins booting the system.
If bootdelay is set to -1, automatic booting is fully disabled. If bootdelay is set to -2, the system boots immediately and disables any attempt to abort the sequence (e.g., via Ctrl+C).
2.2.4 bootcmd
This variable specifies the exact command sequence or macro executed by U-BOOT when initiating an automatic boot. bootcmd stores a series of concatenated U-BOOT commands. When the U-BOOT autoboot sequence fires, it executes the operations defined within bootcmd sequentially.
2.2.5 bootargs
This variable holds the command-line argument vector passed from U-BOOT to the operating system kernel or binary image payload during the boot invocation. The booted kernel or application parses these parameters to control its low-level operational paradigms and driver initializations.
2.2.6 bootfile
Specifies the default target filename to be downloaded when importing images via the Trivial File Transfer Protocol (TFTP).
2.2.7 bootm_low
Specifies the lowest physical memory boundary address accessible to the bootm initialization routine. This variable is typically omitted, defaulting to the baseline memory configuration.
2.2.8 bootm_mapsize
Defines the total size of the linear memory region mapped and accessible to the Linux kernel during its initial booting phase. This virtual window begins explicitly at the address defined by bootm_low.
2.2.9 bootm_size
Defines the maximum allocation space within memory available to the bootm routine for handling, relocating, and decompressing input image files.
2.2.10 updatefile
Designates the source file path and location on the TFTP server when performing firmware or software updates via network protocols.
2.2.11 autoload
When autoload is configured explicitly to no, the bootp and dhcp routines only poll the network BOOTP server to pull environment configurations and network definitions without actually pulling the primary system image from the server into physical memory.
2.2.12 fdt_high
Specifies the highest physical memory address boundary that the Flattened Device Tree (FDT) can occupy.
2.2.13 initrd_high
When this variable is omitted, the initrd image payload is automatically copied to the highest available region of physical memory. When explicitly configured, initrd_high restricts the maximum memory address ceiling available for the initrd allocation.
2.2.14 ipaddr
Configures the local IP address for the network interface. Note that this configuration is strictly valid while executing operations within the U-BOOT context. Once control passes to Linux or another operating system, the IP address will be dynamically acquired or statically bound based on user-space network configurations. The following sequence establishes an IP address of 192.168.1.1:
setenv ipaddr 192.168.1.1
Executing saveenv writes this environment configuration to non-volatile storage.
2.2.15 loadaddr
Defines the default baseline memory load address utilized by utilities like bootp, dhcp, rarpboot, and loadb. As analyzed in subsequent boot sequence chapters, the explicit load address of an image payload is typically governed by the loadaddr field embedded inside the uImage file header, or by properties defined within the Device Tree. When no destination load address is specified anywhere, the value of the loadaddr environment variable acts as the absolute fallback target.
2.2.16 serverip
Specifies the IP address of the remote TFTP server, queried directly by the tftpboot network infrastructure.
2.2.17 bootretry
Defines the maximum threshold of sequential boot attempts before U-BOOT declares a definitive boot failure condition.
2.2.18 image
Specifies the exact filename of the target application or kernel image to be executed via bootm.
2.2.19 fdtfile
On platforms with Device Tree support, this variable defines the filename of the compiled binary Device Tree Blob (DTB) describing the target system's hardware configurations.
2.2.20 fdt_addr
Specifies the physical memory destination address where the Device Tree Blob (DTB) is loaded.
2.2.21 ramdisk
Specifies the filename of the primary RAM file system (ramdisk) image payload.
2.2.22 ramdisk_addr
Defines the exact physical memory target address where the RAM file system is imported and mounted.
Note: U-BOOT supports numerous other standard environment variables which are omitted here for brevity.
2.2.23 User-Defined Environment Variables
Users can instantiate custom environment variables arbitrarily, bounded only by the physical storage capacity allocated for the environment block. U-BOOT variables are categorized into local variables and global variables (the latter commonly referenced as environment variables), and can be further subdivided into simple variables and recursive variables. A simple variable maps a unique literal name directly to a string literal value, using the following format:
setenv <varname> <variable_value>
For example:
=> setenv kernelName ubuntu
=> printenv kernelName
=> kernelName=ubuntu
=>
A recursive variable is defined when a variable's value payload itself references one or more embedded variables. Within a recursive variable definition, the nested variables are not expanded immediately; instead, they persist inside the string as raw variable references. Expansion occurs exclusively when the parent macro variable is executed via the run command, substituting the variable references with their live values. The following sequence shows how a recursive variable is declared and processed:
=> setenv displayBytes md.b \${addr} \${bytes}
=> printenv displayBytes
=> displayBytes=md.b ${addr} ${bytes}
=> setenv addr 0b000000
=> setenv bytes 10
=> run displayBytes
0b000000: 00 00 00 00
0b000004: 00 00 00 00
0b000008: 00 00
In this scenario, setenv displayBytes md.b \${addr} \${bytes} defines the recursive target macro variable displayBytes with the literal string content md.b ${addr} ${bytes}. The backslash \ escape token functions to suppress the immediate expansion of the addr and bytes variables during definition. The ${} token sequence acts as the runtime evaluation operator that replaces the symbolic name with its current data value. When the recursive variable displayBytes is evaluated via run, the variable references addr and bytes expand dynamically, forcing the underlying memory display routine md.b to execute using the live values of those variables rather than their literal names.
Recursive variables are heavily integrated within scripting architectures. Scripting provides exceptional programmatic capability, allowing engineers to enforce highly complex system-wide control flows. The subsequent section comprehensively details the mechanics of U-BOOT script engineering.